-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Export with share theme #5830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export with share theme #5830
Conversation
|
/gemini review |
d06008b to
b1f8d44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new 'share' export format, which generates a static HTML site using the share theme. This is a significant and well-executed feature. The refactoring of the export logic into a provider-based pattern is a major improvement for maintainability and extensibility. My review includes suggestions to improve an error message, optimize HTML processing, clarify some confusing code, and enhance the accuracy of syntax highlighting.
| for (const codeEl of document.querySelectorAll("pre code")) { | ||
| const highlightResult = highlightAuto(codeEl.innerText); | ||
| codeEl.innerHTML = highlightResult.value; | ||
| codeEl.classList.add("hljs"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The syntax highlighting uses highlightAuto, which guesses the language and can be inaccurate. Code blocks in Trilium usually have a language-xxx class. This information should be extracted and used with highlight(text, { language: 'xxx' }) for more accurate highlighting, which is consistent with how client-side highlighting is handled.
You'll need to import highlight alongside highlightAuto from @triliumnext/highlightjs.
for (const codeEl of document.querySelectorAll("pre code")) {
const language = Array.from(codeEl.classList).find(cls => cls.startsWith('language-'))?.substring('language-'.length);
const text = codeEl.innerText;
let highlightResult;
try {
highlightResult = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);
}
catch (e) {
highlightResult = highlightAuto(text);
}
codeEl.innerHTML = highlightResult.value;
codeEl.classList.add("hljs");
}| if (content.length < 100_000) { | ||
| content = html.prettyPrint(content, { indent_size: 2 }) | ||
| } | ||
| content = this.rewriteFn(content as string, noteMeta); | ||
| return content; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
No description provided.